Data Wrangling

# Read in the CA DFW Oil Spill Incident Tracking data
ca_oil <- read_sf(here("ds394"), layer = "ds394") %>% 
  clean_names()

# Check the projection:
st_crs(ca_oil) # EPSG = 3310

# Read in the CA county data (TIGER shapefile):
ca_counties <- read_sf(here("ca_counties"), layer = "CA_Counties_TIGER2016") %>% 
  clean_names() %>% 
  select(name)

# Check the projection
st_crs(ca_counties) # EPSG = 3857

# Transform ca_counties into ca_oil
ca_counties <- st_transform(ca_counties, st_crs(ca_oil))

Interactive map

tmap_mode("view")

tm_basemap("Esri.WorldStreetMap") +
tm_shape(ca_counties) +
  tm_fill(col = "forestgreen", alpha = 0.75) +
  tm_borders(col = "black") +
tm_shape(ca_oil) +
  tm_dots(col = "gold",
          alpha = 0.75) 

Static Chloropleth

# filter for inland only
ca_oil_static <- ca_oil %>% 
  filter(inlandmari == "Inland") 

chlor_data <- ca_counties %>%
  st_join(ca_oil_static) %>% 
  count(localecoun)


chlor_palette <- c("skyblue", "steelblue", "dodgerblue", 
                   "royalblue", "blue", "navyblue")

ggplot(data = chlor_data) +
  geom_sf(aes(fill = n), color = "white", size = 0.1) +
  scale_fill_gradientn(colors = chlor_palette) + # this one is good
  # scale_fill_gradient(low = "skyblue", high = "midnightblue") +
  theme_void() +
  labs(caption = "Chloropleth of counts of inland oil spills in 2008 in California",
       fill = "Number of oil spills\nwithin county") +
  theme(legend.title = element_text(face = "bold", size = 12, color = "black"),
        legend.text = element_text(face = "bold", size = 11, color = "black"),
        legend.position = "right",
        plot.caption = element_text(face = "bold", size = 11, color = "black"),
        plot.background = element_rect(fill = "white",
                                       color = "white"))

# g11 <-  g1 + plot_annotation(caption = "Chloropleth of counts of inland oil spills in 2008 in California",
#                      title = "Number of oil spills\nwithin county")  
# g11 &  theme(plot.background = element_rect(fill = "#222222",
#                                        color = "#222222"),
#         legend.title = element_text(face = "bold", size = 12, color = "white"),
#         legend.text = element_text(face = "bold", size = 11, color = "white"),
#         legend.position = "right",
#         plot.caption = element_text(face = "bold", size = 11, color = "white"))

# g1 & theme(plot.background = element_rect(fill = "#222222",
#                                                  color = "#222222"))

#### not working ugh